
package combat.dudes.client.gui;

import javax.swing.ImageIcon;
import javax.swing.JInternalFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;

import combat.dudes.DudesFunctions;
import combat.dudes.client.ClientApp;


/**
 * @author Laurens Andriessen
 * @version 1.0
 */
public class ClientGUIInternalWindow extends JInternalFrame {

	private static final long serialVersionUID = 1L;

	public int id;
	private int X, Y, W, H;
	public JPanel myBodyPanel;

	public ClientGUIInternalWindow(int id, String title, String icon, JPanel panel) {
		this(id, title, 0, 0, 0, 0, icon, panel);
	}

	public ClientGUIInternalWindow(int id, String title, int x, int y, int w, int h, String icon, JPanel panel) {
		super(title, false, true, false, false);
		this.id = id;
		this.X = x;
		this.Y = y;
		this.W = w;
		this.H = h;
		this.setBounds(X, Y, W, H);

		this.setFocusable(true);
		this.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
		this.setFrameIcon(new ImageIcon(DudesFunctions.File.getIcon(icon)));
		try {
			this.setIcon(false); // Leave this false, as this'll cause bugs in the frame-focusing-system
		} catch(Exception e) {
			ClientApp.onError("Couldn't set setIcon(false)", e, false);
		}

		// this.setVisible(true);
		// System.out.println(this.getTitle() + ":\t" + this.getX() + ", " + this.getY());
		// ClientApp.Log("Created window '" + this.title + "'");

		synchronized(panel) {
			this.myBodyPanel = panel;
			this.add(panel);
		}
		// ClientApp.Log("Attached panel to '" + this.title + "'");
	}

	public void setSize(int x, int y, int w, int h) {
		this.X = x;
		this.Y = y;
		this.W = w;
		this.H = h;
		this.setBounds(X, Y, W, H);
	}

	public void restoreWindow() {
		this.setBounds(X, Y, W, H);
		setVisible(true);
		try {
			setIcon(false);
		} catch(Exception e) {
			ClientApp.onError("Couldn't restore window while it's iconized", e, false);
		}
	}

}
